<%@ page import="nl.hva.web.mvcwebapp.chat.*" errorPage="error.jsp" %>
<HTML>
    <HEAD>
        <TITLE>You have logged out</TITLE>
        <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/chat/chat.css">
        <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/style.css">
        <META http-equiv="pragma" content="no-cache">
        <script language="javascript">
            <!--
            setTimeout("self.close();",10000)
            //-->
        </script> 
    </HEAD>

    <BODY class="linen orange">
        <div class="wrapper">
            <div class="content-wrapper">
                <%@ include file="/chat/header.jsp" %>
                <div align="center">
                    <center>

                        <%
                            String nickname = (String) session.getAttribute("nickname");
                            if (nickname != null && nickname.length() > 0) {
                                ChatRoomList roomlist = (ChatRoomList) application.getAttribute("chatroomlist");
                                ChatRoom chatRoom = roomlist.getRoomOfChatter(nickname);
                                chatRoom.addMessage(new Message("system", nickname + " has logged out.", new java.util.Date().getTime()));
                                if (chatRoom != null) {
                                    chatRoom.removeChatter(nickname);
                                    session.invalidate();
                                    out.write("<font color=\"blue\">You successfully logged out</font><br>");
                                    out.write("Dit venster wordt automatisch afgesloten.");
                                    //out.write("<a href=\"" + request.getContextPath() + "/chat/login.jsp\">Login again</a>");
                                } else {
                                    //out.write("<h3><font color=\"red\">Unable to logout</font></h3>");
                                    response.sendRedirect(request.getContextPath() + "/chat/login.jsp");
                                }
                            } else {
                                response.sendRedirect(request.getContextPath() + "/chat/login.jsp");
                            }
                        %>
                    </center>
                </div>
            </div>
        </div>
    </BODY>
</HTML>